package com.daocao.hua.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.daocao.hua.R;
import com.daocao.hua.adapter.base.ItemAdapter;
import com.daocao.hua.model.PaymentNoticeListModel;
import com.daocao.hua.util.DateTime;
import com.daocao.hua.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class V3MyRepayRecordAdapter extends ItemAdapter<PaymentNoticeListModel.DataBean, V3MyRepayRecordAdapter.DefaultHolder> {

    private final int x30;
    private Context context;
    private int color;

    public V3MyRepayRecordAdapter(Context context) {
        super(context);
        this.context = context;
        x30 = context.getResources().getDimensionPixelSize(R.dimen.x30);
        color = 0xff616185;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_repay_v3, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        PaymentNoticeListModel.DataBean item = getItem(position);

        switch (item.order_status) {
            case "0":
                holder.txtStatus.setText("还款中");
                holder.txtStatus.setShapeSolidColor(0xffFF7A31).setUseShape();
            case "1":
                holder.txtStatus.setText("还款失败");
                holder.txtStatus.setShapeSolidColor(0xffFE5A59).setUseShape();

            case "2":
                holder.txtStatus.setText("还款成功");
                holder.txtStatus.setShapeSolidColor(0xff3BCF8F).setUseShape();

        }
        holder.txtOrderNo.setText("订单编号：" + item.notice_sn);
        holder.txtBorrowTime.setText(DateTime.toDateMinute(Long.valueOf(item.create_time) * 1000));

        Spanned txt_left = Spans.with(context).font("借款金额:￥" + item.order_money, x30, color).
                font("\n实收金额:￥" + item.money, x30, color).
                font("\n还款方式:" + item.payment_name, x30, color).
                font("\n还款账户:" + item.memo, x30, color).
                build();
        holder.txtInfoLeft.setText(txt_left);

        Spanned txt_right = Spans.with(context).font("需还金额:￥" + item.repay_money, x30, color).
                font("\n逾期费用:￥" + item.money, x30, color).
                font("\n还款方式:" + item.payment_name, x30, color).
                font("\n还款账户:" + item.memo, x30, color).
                build();
        holder.txtInfoRight.setText(txt_right);
        holder.btnWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClickWechat();
                }
            }
        });
        holder.btnHetong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClickHetong("");
                }
            }
        });
    }


    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_status)
        SuperButton txtStatus;
        @BindView(R.id.txt_info_left)
        TextView txtInfoLeft;
        @BindView(R.id.txt_info_right)
        TextView txtInfoRight;
        @BindView(R.id.fl_info)
        FrameLayout flInfo;
        @BindView(R.id.txt_order_no)
        TextView txtOrderNo;
        @BindView(R.id.btn_hetong)
        TextView btnHetong;
        @BindView(R.id.txt_borrow_time)
        TextView txtBorrowTime;
        @BindView(R.id.btn_wechat)
        ImageView btnWechat;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClickHetong(String id);

        void onClickWechat();
    }
}
